package com.godme.prop;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import redis.clients.jedis.HostAndPort;

import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

@Component
@ConfigurationProperties(prefix = JedisClusterProperties.PREFIX)
public class JedisClusterProperties {

    public static final String PREFIX = "spring.jedis.cluster";


    private int timeout;
    private String nodes;

    private Set<HostAndPort> hostAndPorts;

    public Set<HostAndPort> getHostAndPorts() {
        if(Objects.isNull(hostAndPorts)){
            hostAndPorts = Arrays.stream(nodes.split(",")).map(e -> e.trim()).map(HostAndPort::parseString).collect(Collectors.toSet());
        }
        return hostAndPorts;
    }


    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public String getNodes() {
        return nodes;
    }

    public void setNodes(String nodes) {
        this.nodes = nodes;
    }
}
